package com.thunder.reader.weibo;

import com.thunder.reader.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ProgressBar;

public class LogonWeiboActivity extends Activity {
    private static final String TAG = "LogonWeiboActivity";
    private WebView mWebView;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final Intent intent = getIntent();
        Log.e(TAG, "intent is + " + intent);
        final String oauthUrl = intent.getStringExtra("oauth_url");
        if (TextUtils.isEmpty(oauthUrl)) {
            Log.e(TAG, "fuck, fuck, url from passer is empty");
            finish();
        }
        Log.e(TAG, "url from oauth is: " + oauthUrl);
        setContentView(R.layout.logonweibo);
        mWebView = (WebView) findViewById(R.id.logon_weibo_view);
        final ProgressBar progressbar = (ProgressBar) findViewById(R.id.logon_weibo_progress);
        progressbar.setProgress(0);
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setSaveFormData(true);
        webSettings.setSavePassword(true);
        webSettings.setSupportZoom(false);
        webSettings.setBuiltInZoomControls(false);
        webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
        mWebView.loadUrl(oauthUrl);
        mWebView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                progressbar.setProgress(newProgress);
                if (newProgress == 100) {
                    progressbar.setVisibility(View.GONE);
                }
            }
        });
    }
}